<template>
	<view>
		<u-loading-page :loading="pageLoading"></u-loading-page>
		<u-empty mode="list" v-if="listData.length === 0" :style="{height: `${screenHeight}px`}" />
		<scroll-view class="" v-if="!pageLoading && listData.length > 0" scroll-y refresher-enabled show-scrollbar
			:refresher-triggered="triggered" @refresherrefresh="$u.throttle(onRefresherrefresh, 200)"
			@scrolltolower='$u.throttle(onScrolltolower,1000)' :style="{height: `${screenHeight}px`}">
			<!-- 列表 -->
			<view class="p-l-30 p-r-30">
				<view class="item" v-for="(item, index) in listData" :key="index" @tap="itemClick(item)">
					<view>
						<view class="name">{{item.label}}</view>
					</view>
				</view>
			</view>

		</scroll-view>
	</view>
</template>

<script>
	import {
		listOptionsByStoreId
	} from '@/apis/bsd/store-position.js'

	export default {
		data() {
			return {
				storeId: null,
				screenHeight: 0,
				pageLoading: true,
				triggered: false,
				listData: [],
				pageInfo: {
					current: 1, // 当前页
					size: 10, // 每页数据条数
					sort: '', // 排序字段
					order: 'desc', // 排序方向
					total: 0 // 总数居量
				}
			}
		},
		onLoad() {
			const storeId = this.$Route.query.storeId
			this.storeId = storeId
			storeId && this.listPage(storeId)
		},
		onReady() {
			const sysInfo = uni.getSystemInfoSync()
			this.screenHeight = sysInfo.windowHeight
		},
		methods: {
			listPage(storeId) {
				this.triggered = true
				const params = {
					page: this.pageInfo,
					data: {
						storeId
					}
				}
				listOptionsByStoreId(storeId).then(res => {
					if (!res.data.flag) return
					const records = res.data.data || []
					this.listData.push(...records)
				}).finally(_ => {
					this.triggered = false
					this.pageLoading = false
				})
			},
			itemClick(row) {
				uni.$emit("on-selected-store-position", row)
				this.$Router.back()
			},
			onRefresherrefresh() {
				this.listData = []
				this.listPage(this.storeId)
			},
			onScrolltolower() {}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		border-radius: 10rpx;
		background: #fff;
		padding: 30rpx;
		margin-top: 30rpx;

		.name {
			font-size: 40rpx;
		}
	}
</style>
